package Kuaishou;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

import org.apache.commons.lang3.StringUtils;

/**
 * @author leiwenkang <leiwenkang@kuaishou.com>
 * Created on 2020-09-15
 */
public class Test06日期测试 {
    private static final String DEFAULT_SYS_DATE_FMT = "yyyyMMdd";

    public static void main(String[] args) {
        System.out.println(date2str(addDay(new Date(), 60)));
    }

    private static Date addDay(Date date, int day) {
        if (date == null) {
            return null;
        }
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.add(Calendar.DAY_OF_MONTH, day);
        return calendar.getTime();
    }

    /**
     * 字符日期串转换成DATE对象
     */
    private static String date2str(Date date) {
        if (date == null) {
            return null;
        }
        try {
            SimpleDateFormat sdf = new SimpleDateFormat(DEFAULT_SYS_DATE_FMT);
            return sdf.format(date);
        } catch (Exception ex) {
            return null;
        }
    }
}
